package com.oracle.application.controller;


import com.oracle.application.entity.vo.OrderConfirmVo;
import com.oracle.application.entity.vo.OrderSubmitVo;
import com.oracle.application.entity.vo.OrdersVo;
import com.oracle.application.entity.vo.R;
import com.oracle.application.service.IOrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController

@RequestMapping("/orders")
@Slf4j
public class OrdersController {
    @Autowired
    private IOrdersService iOrdersService;
    @GetMapping("/config")
public R<OrderConfirmVo> confirm(){
    OrderConfirmVo orderConfirm=iOrdersService.createorderConfirm();

        return new R<OrderConfirmVo>(200,"success",orderConfirm);
}
@PostMapping("/submit")
public R submit(@RequestBody OrderSubmitVo orderSubmitVo) throws Exception{
        log.info("订单提交后的订单信息:{}",orderSubmitVo);
       Map<String,Object>map=this.iOrdersService.submitOrder(orderSubmitVo);
       if (map.get("code")!=null&&map.get("code").equals(500)){
         return   new R(201,"请不要重复创建订单",null);

       }
    OrdersVo ordersVo=(OrdersVo)map.get("data");

    return    new R(200,"ok",ordersVo);
}

}
